home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / esa / examples / sss / code / misc.ei < prev    next >
Text File  |  1999-01-25  |  7KB  |  233 lines

  1. *******************************************************************************
  2. * Init v1.1.1
  3. *******************************************************************************
  4. * INFO    execute some system inits
  5. * SYNOPSIS    success = Init[CmdLnPtr,CmdLnLen]
  6. *    d0      a0       d0.w
  7. * IN    CmdLnPtr    ptr to the shell command line string
  8. *    CmdLnLen    length in chars of the command line
  9. * OUT    success    0=ERROR
  10. * MODIFIES    _DOSBase    dos.library ptr
  11. *    _StdOut    standard output filehandle
  12. *    CmdLn    command line (NULL-terminated) string
  13. * REQUIRES    _DOSName    address of "dos.library",0
  14. *******************************************************************************
  15.  
  16.     function Init[a0/d0.w],d1/d7/a0-a1/a6:d0.l
  17.  
  18.     moveq.l    #0,d7
  19.  
  20.     subq.w    #1,d0    ;don't copy closing RETURN
  21.     lea.l    CmdLn,a1    ;dest buf
  22.     when.s    {#512»=d0.w} & d0.w
  23.      subq.w    #1,d0    ;"expire" = "dbra"
  24.      expire d0=d0
  25.       move.b    (a0)+,(a1)+    ;copy command line
  26.       addq.l    #1,d7
  27.      nexp
  28.     ewhen
  29.     clr.b    (a1)    ;NULL-terminated
  30.  
  31.     movea.l    4.w,a6
  32.     lea.l    _DOSName,a1
  33.     moveq.l    #36,d0    ;at least KS 2.0
  34.     jsr    (_LVOOpenLibrary,a6)
  35.     move.l    d0,_DOSBase
  36.  
  37.     when.s d0
  38.      movea.l    d0,a6
  39.      jsr    (_LVOOutPut,a6)
  40.      move.l    d0,_StdOut    ;still true (~0)
  41.     ewhen
  42.  
  43.     efunc
  44.  
  45. *******************************************************************************
  46. * CleanUp v1.0.3
  47. *******************************************************************************
  48. * INFO    frees allocated system resources
  49. * SYNOPSIS    CleanUp[]
  50. * REQUIRES    _DOSBase    dos.library ptr
  51. *******************************************************************************
  52.  
  53.     procedure CleanUp[],d0-d1/a0-a1/a6
  54.  
  55.     move.l    InFileHnd,d1    ;source file handle
  56.     when.s d1.l
  57.      movea.l    _DOSBase,a6
  58.      jsr    (_LVOClose,a6)
  59.     ewhen
  60.  
  61.     move.l    WrkBufLen,d0    ;free allocated buf
  62.     when.s d0.l
  63.      movea.l    4.w,a6
  64.      movea.l    WrkBufAdr,a1
  65.      jsr    (_LVOFreeMem,a6)
  66.     ewhen
  67.  
  68.     movea.l    _DOSBase,a1
  69.     movea.l    4.w,a6
  70.     jsr    (_LVOCloseLibrary,a6)
  71.  
  72.     moveq.l    #0,d0    ;retcode
  73.     eproc
  74.  
  75. *******************************************************************************
  76. * Print v1.0.0
  77. *******************************************************************************
  78. * INFO    prints a text to the standard output if quiet mode is OFF
  79. * SYNOPSIS    Print[TxtPtr]
  80. *          d2
  81. * IN    TxtPtr    ptr to NULL-terminated text string
  82. * REQUIRES    _DOSBase    dos.library ptr
  83. *    _StdOut    standard output handle
  84. *******************************************************************************
  85.  
  86.     procedure Print[d2],d0-d3/a0-a1/a6
  87.  
  88.     move.b    flags,d0
  89.     andi.b    #1<<F_QUIETMODE,d0
  90.  
  91.     when.s ~d0.b        ;if quiet mode OFF
  92.      movea.l    d2,a0
  93. .findend     tst.b    (a0)+
  94.      bne.s    .findend    ;find end of string
  95.      move.l    a0,d3
  96.      sub.l    d2,d3    ;length
  97.      movea.l    _DOSBase,a6
  98.      move.l    _StdOut,d1
  99.      jsr    (_LVOWrite,a6)
  100.     ewhen
  101.  
  102.     eproc
  103.  
  104. *******************************************************************************
  105. * ShowResult v1.1.1
  106. *******************************************************************************
  107. * INFO    prints out the texts associated to a given errcode
  108. * SYNOPSIS    ShowResult[ErrCode]
  109. *               d0
  110. * IN    ErrCode    0=OK, else E_xxxxxx (see defs.i)
  111. *******************************************************************************
  112.  
  113.     procedure ShowResult[d0]
  114.     when.s d0
  115.      Print[#txt_error]    ;"ERROR: "
  116.     ewhen
  117.     Print[(ErrTab.l,d0.l*4)]    ;print msg
  118.     eproc
  119.  
  120. *******************************************************************************
  121. * SkipSpaces v1.0.0
  122. *******************************************************************************
  123. * INFO    starting from the current position in a string, returns the
  124. *    position of the 1st character different from ' '
  125. * SYNOPSIS    SkipSpaces[StrPtr]
  126. *               a0
  127. * IN    StrPtr    ptr to a string
  128. * MODIFIES    a0.l    position of the 1st char <>' '
  129. *******************************************************************************
  130.  
  131.     procedure SkipSpaces[a0]
  132. .find    cmpi.b    #' ',(a0)+
  133.     beq.s    .find
  134.     subq.l    #1,a0
  135.     eproc
  136.  
  137. *******************************************************************************
  138. * Valu v1.0.2
  139. *******************************************************************************
  140. * INFO    converts a decimal ASCII string to an unsigned long integer
  141. * SYNOPSIS    IntVal = Valu[StrPtr]
  142. *    d0    a0
  143. * IN    StrPtr    ptr to numerical string
  144. * OUT    IntVal    unsigned integer
  145. * MODIFIES    a0.l    ptr after string
  146. * NOTE    it stops at the 1st char not inside ['0'...'9']
  147. *******************************************************************************
  148.  
  149.     function Valu[a0],d1-d2:d0
  150.     moveq.l    #0,d0
  151.     moveq.l    #0,d1
  152.     do
  153.      move.b    (a0)+,d1    ;get a digit (d)
  154.      subi.b    #'0',d1    ;convert to int
  155.      bcs.s    .exit    ;if d<0...
  156.      cmpi.b    #9,d1
  157.      bhi.s    .exit    ;if d>9...
  158.      move.l    d0,d2    ;IntVal
  159.      add.l    d0,d0    ;2*IntVal
  160.      lsl.l    #3,d2    ;8*IntVal
  161.      add.l    d2,d0    ;10*IntVal
  162.      add.l    d1,d0    ;10*IntVal+d -> IntVal
  163.     loop
  164. .exit
  165.     efunc
  166.  
  167. *******************************************************************************
  168. * Stru v1.0.0
  169. *******************************************************************************
  170. * INFO    converts an unsigned long integer to a NULL-terminated, decimal
  171. *    ASCII string
  172. * SYNOPSIS    Stru[Int,Dest,Len]
  173. *         d0  a0   d1
  174. * IN    Int    integer to convert
  175. *    Dest    ptr to destination buffer
  176. *    Len    the string will be exactly Len chars long
  177. *        (MUST be >0!!!)
  178. * NOTE    the destination buffer MUST be at least Len+1 bytes long!
  179. *******************************************************************************
  180.  
  181.     procedure    Stru[d0/a0/d1],d0-d2/a0
  182.     adda.l    d1,a0    ;last digit adr+1
  183.     clr.b    (a0)    ;final BLANK
  184.     subq.l    #1,d1
  185.     expire d1=d1
  186.      divul.l    #10,d2:d0    ;last digit
  187.      addi.b    #'0',d2    ;convert to ASCII
  188.      move.b    d2,-(a0)    ;store
  189.     nexp
  190.     eproc
  191.  
  192. *******************************************************************************
  193. * GetFileSize v1.0.1
  194. *******************************************************************************
  195. * INFO    returns the size in bytes of a file
  196. * SYNOPSIS    Size=GetFileSize[Hnd]
  197. *    d0    d1
  198. * IN    Hnd    filehandle
  199. * OUT    d0    0 on failure
  200. * REQUIRES    _DOSName    address of "dos.library",0
  201. * NOTE    uses TmpBuf (must be on a 4 bytes boundary)
  202. *******************************************************************************
  203.  
  204.     function GetFileSize[d1],d1-d2/a0-a1/a6:d0
  205.     move.l    #TmpBuf,d2
  206.     movea.l    _DOSBase,a6
  207.     jsr    (_LVOExamineFH,a6)
  208.     when.s d0.l
  209.      lea.l    TmpBuf,a0
  210.      move.l    (fib_Size,a0),d0
  211.     ewhen
  212.     efunc
  213.  
  214. *******************************************************************************
  215. * ChkBrk v1.0.0
  216. *******************************************************************************
  217. * INFO    checks if the user is pressing CTRL-C
  218. * SYNOPSIS    ErrCode=ChkBrk[]
  219. *    d0
  220. * OUT    ErrCode    E_USRBRK if pressed, 0 otherwise
  221. *******************************************************************************
  222.  
  223.     function ChkBrk[],d1/a0-a1/a6:d0
  224.     movea.l    4.w,a6
  225.     moveq.l    #0,d0
  226.     move.l    #SIGBREAKF_CTRL_C,d1    ;chk & clr this signal
  227.     jsr    (-306,a6)    ;SetSignal()
  228.     btst.l    #SIGBREAKB_CTRL_C,d0    ;if the signal bit
  229.     sne.b    d0    ;was ON, then return
  230.     andi.b    #E_USRBRK,d0    ;the appropriate ErrCode
  231.     extb.l    d0
  232.     efunc
  233.